package cn.powertime.evaluation.web.controller;

import cn.powertime.evaluation.entity.KbKnowledgeBase;
import cn.powertime.evaluation.entity.SysBanner;
import cn.powertime.evaluation.facade.IndexFacade;
import cn.powertime.evaluation.vo.PageVo;
import cn.powertime.evaluation.vo.WebRespIndexCourseListVo;
import cn.powertime.evaluation.vo.WebRespIndexPostingsListVo;
import cn.powertime.evaluation.vo.ZcRespIndexListVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.List;

@RestController
@RequestMapping("/web/index")
@Api(value = "/web/index", tags = "PC端首页接口", produces = MediaType.ALL_VALUE)
@Validated
public class WebIndexController extends BaseController {

    @Autowired
    private IndexFacade webIndexFacade;

    @ApiOperation(value = "banner列表", notes = "")
    @GetMapping("/list/{type}")
    @ApiImplicitParam(paramType = "path", dataType = "Integer", name = "type", value = "1:PC首页，2，APP首页，3：PC政策宣传，4：PC知识库，5：PC企业自查", required = true)
    public Object list(@PathVariable("type") Integer type) {
        List<SysBanner> list = webIndexFacade.bannerList(type);
        return success(list);
    }

    @ApiOperation(value = "首页课程列表",response = WebRespIndexCourseListVo.class)
    @PostMapping(value = "/courseList/{type}")
    @ApiImplicitParam(paramType = "path", dataType = "Integer", name = "type", value = "课程类型1：成为测评师 ，2：测评师训练场", required = true)
    public Object courseList(@PathVariable("type") @NotNull(message = "课程类型不能为空") Integer type) {
        List<WebRespIndexCourseListVo> list = webIndexFacade.courseList(type);
        return success(list);
    }

    @ApiOperation(value = "首页帖子列表",response = WebRespIndexPostingsListVo.class)
    @PostMapping(value = "/postingsList")
    public Object list(@RequestBody PageVo pageVo) {
        IPage<WebRespIndexPostingsListVo> list = webIndexFacade.postingsList(pageVo);
        return success(list);
    }

    @ApiOperation(value = "首页知识库列表", response = WebRespIndexCourseListVo.class)
    @GetMapping(value = "/knowledgeBaseList")
    @ApiImplicitParam(name = "type", value = "知识库类型，1:热门知识，2:知识贡献", required = true, dataType = "Integer")
    public Object knowledgeBaseList(@NotNull(message = "知识库类型不能为空") @Max(value = 2, message = "知识库类型最大值为2") @Min(value = 1, message = "知识库类型最小值为1") @RequestParam(defaultValue = "1") Integer type) {
        List<KbKnowledgeBase> list = webIndexFacade.knowledgeBaseList(type);
        return success(list);
    }


    @ApiOperation(value = "政策宣传列表", response = ZcRespIndexListVo.class)
    @GetMapping("/zcList")
    public Object zcList() {
        List<ZcRespIndexListVo> list = webIndexFacade.zcList();
        return success(list);
    }
}
